package com.rentong.wx.cust.controller;

import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.rentong.wx.cust.service.CustOrderPayService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 支付流水
 *
 * @author zhangle
 * @email 459343178@qq.com
 * @date 2024-12-24 14:42:32
 */
@RestController
public class CustOrderPayController {

    @Autowired
    private CustOrderPayService custOrderPayService;


    //微信小程序，支付回调
    @RequestMapping("/back/wx/pay/notify")
    public String payNotify(HttpServletRequest request) {
        try {
            String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
            custOrderPayService.payNotify(xmlResult);
        } catch (Exception e) {
            //log.error("微信回调结果异常,异常原因{}", e.getMessage());
            return WxPayNotifyResponse.fail(e.getMessage());
        }
        return WxPayNotifyResponse.success("处理成功!");
    }




}
